package com.sxx.beautifulcity.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.sxx.beautifulcity.R;
import com.sxx.beautifulcity.database.UserHelper;
import com.sxx.beautifulcity.entity.greendao.UserDaoEntity;

import java.util.List;

/**
 * Created by dllo on 15/11/4.
 */
public class FindPawActivity extends DialogBaseActivity implements View.OnClickListener {
    private TextView getpswTv , titleTv;
    private EditText usernameEt;
    private Button startBtn;
    private UserHelper helper;
    private ImageView backBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_find_psw);
        initView();
    }

    /***
     * 初始化
     */
    private void initView() {
        helper = new UserHelper();

        getpswTv = (TextView) findViewById(R.id.getpswTv);
        usernameEt = (EditText) findViewById(R.id.usernameEt);
        startBtn = (Button) findViewById(R.id.startBtn);
        startBtn.setOnClickListener(this);
        titleTv = (TextView) findViewById(R.id.titleTv);
        backBtn = (ImageView) findViewById(R.id.backIV);
        titleTv.setText("找回密码");
        backBtn.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.startBtn:
                queryDatabase();
                break;
            case R.id.backIV:
                Intent intent = new Intent(this , LoginActivity.class);
                startActivity(intent);
                finish();
                overridePendingTransition(R.anim.left_out, R.anim.right_into);
                break;
        }
    }
    private void queryDatabase(){
        showDialog();
        String name = usernameEt.getText().toString();
        String num = usernameEt.getText().toString();
        List<UserDaoEntity> entity = helper.queryName(name , num);
        getpswTv.setText(entity.get(0).getUserPsw());
        dismissDialog();
    }
}
